Title: Showing Products When No Products Can Be Found

Publish Date: Fri, 28 Jul 2017 06:18:18 +0000

Categories: Uncategorized

Content:

Isn’t the title a bit confusing? I really had no idea about how to explain what this article is about exactly without writing a title that is 20k characters long.

So, let’s try to explain what it is about here.

If a potential customer on your site tries to search for a product it may happen that they won’t find anything. Maybe because the keyword used is too specific, or maybe just because you don’t have what they want. They will land on a page with a message telling them that no products can be found.

How can you try to sell something anyway from that page?



Showing Products When Nothing Else Can Be Found

What we want to do here is to show some products for the customer when no other products can be found.

You may want to show your featured products or just some random products. In this case, we’ll show the 4 most recent products.

So, open the file functions.php in wp-content/themes/your-child-theme-name/ and add this code at the end of the file:

https://gist.github.com/eb30d9646eddbbd5b3f8aebce7febdff

This code is pretty clear. It prints the title You may be interested in… and then a list of four products. You can increase the number of products shown of course, but I’d suggest to not print too many.

Are you wondering how it looks? Here is a screenshot of my local test site with [ablank href="https://woocommerce.com/storefront/"]Storefront[/ablank]:

[caption id="attachment_3288" align="alignnone" width="2320"] Searching for a keyword does not return any result, but the most four recent products are shown.[/caption]

If you want to show some other kind of products, you can have a look at the [ablank href="https://docs.woocommerce.com/document/woocommerce-shortcodes/"]shortcodes available in WooCommerce[/ablank].
